package com.winchain.chainbill.bill.biz.send.rx;

import com.shell.bee.base.utils.DateUtil;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.governor.modules.message.keyword.SysSndApplyKeyword;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.stereotype.Component;

@Component
public class BillMsgSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbSnd>> {
	public void onApplicationEvent(BillEvent<CbSnd> t) {
		CbRec cbRec = t.getBill().getRec();
		CbSnd cbSnd = (CbSnd) t.getBill().getSource();

		String template = "MT01201";
		SysSndApplyKeyword keyWord = new SysSndApplyKeyword();
		keyWord.setBillAmt(String.valueOf(cbRec.getBillAmt()));
		keyWord.setSellerNm(cbSnd.getSellerNm());
		keyWord.setSndDate(DateUtil.parseDate(cbSnd.getCreateTime(), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"));
		keyWord.setContactorName(CommonDataUtil.getUserName());

		String senderId = CommonDataUtil.getUserId();

		MessageSender.sendMessageByTmpl(senderId, template, keyWord, cbSnd.getBuyerId());
	}
}
